home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************************
- * *
- * FDT.CPP: Transforms the input data into the frequency domain and vice versa *
- * *
- * Copyright (C) 2000 Andrei Grecu *
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program; if not, write to the Free Software *
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
- * *
- * If you have questions, bug reports regarding my code please contact me at: *
- * andrei.grecu@aon.at *
- * *
- * Home page: *
- * http://members.aon.at/grxpage/index.htm *
- * *
- **********************************************************************************/
-
- #include "precomp.h"
- #include <windows.h>
- #include <math.h>
- #include <stdio.h>
- #include <rfftw.h>
-
- #include "misc.h"
- #include "fdt.h"
- #include "fftsg.h"
-
- ULONG maxn, buflen;
-
- HGLOBAL ht, hip, hw;
- LPINT ip;
- LPDOUBLE t, w;
-
- void FDT(const LPSHORT src, const LPCOEF dest) {
-
- ULONG k;
-
- for(k = 0; k < buflen; k++) {
- dest[k] = src[k];
- }
-
- dest[0] *= 0.5;
-
- //rdft(buflen, 1, dest, ip, w);
- ddct(buflen, -1, dest, ip, w);
-
- }
-
- void IFDT(const LPCOEF src, const LPSHORT dest) {
-
- ULONG k;
-
- src[0] *= 0.5;
-
- //rdft(buflen, -1, src, ip, w);
- ddct(buflen, 1, src, ip, w);
-
- for(k = 0; k < buflen; k++) {
- src[k] *= (COEF)2 / buflen;
- if(src[k] > 32767) dest[k] = 32767;
- else if(src[k] < -32767) dest[k] = -32768;
- else dest[k] = (SHORT) round((FLOAT)src[k]);
- }
-
- }
-
- // Initializes the DCT matrix
- void gen_DCTmatrix(ULONG dwbuflen) {
-
- maxn = (DWORD)(log(buflen) / log(2));
- buflen = dwbuflen;
-
- if(hip) {
- GlobalUnlock(ht);
- GlobalFree(ht);
-
- GlobalUnlock(hip);
- GlobalFree(hip);
-
- GlobalUnlock(hw);
- GlobalFree(hw);
- hip = 0;
- }
-
- ht = GlobalAlloc(GHND, 2*(buflen/2+1) * sizeof(DOUBLE));
- t = (LPDOUBLE) GlobalLock(ht);
-
- hip = GlobalAlloc(GHND, 2+(1<<(int)(log(buflen+0.5)/log(2))/2) * sizeof(INT));
- ip = (LPINT) GlobalLock(hip);
-
- ip[0] = 0;
-
- hw = GlobalAlloc(GHND, buflen*5/4 * sizeof(DOUBLE));
- w = (LPDOUBLE) GlobalLock(hw);
-
- }
-
- // Destroys the DCT matrix
- void destr_DCTmatrix(void) {
-
- if(hip) {
- GlobalUnlock(ht);
- GlobalFree(ht);
-
- GlobalUnlock(hip);
- GlobalFree(hip);
-
- GlobalUnlock(hw);
- GlobalFree(hw);
- hip = 0;
- }
-
- }
-
-